﻿using System;
using System.Collections.Generic;
using System.Text;

namespace System
{
    /// <summary>
    /// 数据转换相关的扩展
    /// </summary>
    public static class DataConvertExtension
    {
        /// <summary>
        /// 转为WPF的<see cref="System.Windows.Point"/>结构
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public static Windows.Point ToWPFPoint(this SharpSoft.Geometries.Point2D point2D)
        {
            return new Windows.Point(point2D.X, point2D.Y);
        }
        /// <summary>
        /// 转为WPF的<see cref="System.Windows.Point"/>结构
        /// </summary>
        /// <param name="point2Ds"></param>
        /// <returns></returns>
        public static Windows.Point[] ToWPFPoints(this SharpSoft.Geometries.Point2D[] point2Ds)
        {
            if (point2Ds == null)
            {
                return null;
            }
            Windows.Point[] ps = new Windows.Point[point2Ds.Length];
            for (int i = 0; i < point2Ds.Length; i++)
            {
                ps[i] = ToWPFPoint(point2Ds[i]);
            }
            return ps;
        }

        public static SharpSoft.Geometries.Point2D ToPoint2D(this Windows.Point p)
        {
            return new SharpSoft.Geometries.Point2D(p.X, p.Y);
        }
        public static SharpSoft.Geometries.Point2D[] ToPoint2Ds(this Windows.Point[] ps)
        {
            if (ps == null)
            {
                return null;
            }
            SharpSoft.Geometries.Point2D[] p2ds = new SharpSoft.Geometries.Point2D[ps.Length];
            for (int i = 0; i < ps.Length; i++)
            {
                p2ds[i] = ToPoint2D(ps[i]);
            }
            return p2ds;
        }

        public static Drawing.Point ToDrawingPoint(this SharpSoft.Geometries.Point2D point2D)
        {
            return new Drawing.Point((int)point2D.X, (int)point2D.Y);
        }

        public static Drawing.Point[] ToDrawingPoint(this SharpSoft.Geometries.Point2D[] point2Ds)
        {
            if (point2Ds == null)
            {
                return null;
            }
            var ps = new Drawing.Point[point2Ds.Length];
            for (int i = 0; i < point2Ds.Length; i++)
            {
                ps[i] = ToDrawingPoint(point2Ds[i]);
            }
            return ps;
        }
    }
}
